<?php
namespace Framework\Library\Validator;

use Phalcon\Validation;
use Phalcon\Validation\Message;
use Phalcon\Validation\Validator;
use Phalcon\Validation\ValidatorInterface;
use Ramsey\Uuid\Uuid;

class UuidValidator extends Validator implements ValidatorInterface
{
    public function validate(Validation $validation, $attribute)
    {
        $uuid = $validation->getValue($attribute);
        if (!Uuid::isValid($uuid)) {
            $validation->appendMessage(new Message('Uuid format error', $attribute, 'Uuid'));

            return false;
        }

        return true;
    }
}
